package com.lkx.farmershop.controller;

import com.lkx.farmershop.common.api.ApiResult;
import com.lkx.farmershop.model.dto.FollowDto;
import com.lkx.farmershop.model.vo.FollowAndFansCount;
import com.lkx.farmershop.model.vo.SimpleUserVo;
import com.lkx.farmershop.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/follow")
public class FollowController {

    @Autowired
    private FollowService followService;

    /**
     *  关注用户
     * @param followDto
     * @return
     */
    @Transactional
    @PostMapping("/followUser")
    public ApiResult<String> followUser(@RequestBody FollowDto followDto) {
        return followService.followUser(followDto);
    }

    /**
     * 获取关注和粉丝数量
     * @param userId
     * @return
     */
    @GetMapping("/getCount")
    public ApiResult<FollowAndFansCount> getCount(@RequestParam("userId") Long userId) {
        return followService.getCount(userId);
    }

    /**
     * 获取关注列表
     * @param userId
     * @return
     */
    @GetMapping("/getFollowList")
    public ApiResult<List<SimpleUserVo>> getFollowList(@RequestParam("userId") Long userId) {
        return followService.getFollowList(userId);
    }

    /**
     * 获取粉丝列表
     * @param userId
     * @return
     */
    @GetMapping("/getFansList")
    public ApiResult<List<SimpleUserVo>> getFansList(@RequestParam("userId") Long userId) {
        return followService.getFansList(userId);
    }

}
